﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DAL;
using DTO;

namespace WEBSITE_BANDEAL.Admin
{
    public partial class KhachHang_Edit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lit_title.Text = "Update thông tin khách hàng";
            if (!IsPostBack)
            {
                LoadData();
            }

        }

        private void LoadData()
        {            
            try
            {
                int id = int.Parse(Request.QueryString["ID"]);
                KHACH_HANG k = KHACH_HANGBUS.GetByID(id);
                if (k != null)
                {
                    MaKH.Value = k.MaKhachHang.ToString();
                    Email.Value = k.Email.ToString();
                    MatKhau.Value = k.MatKhau.ToString();
                    TenKhachHang.Value = k.TenKhachHang.ToString();
                    DiaChi.Value = k.DiaChi.ToString();
                    DienThoai.Value = k.DienThoai.ToString();
                }
            }
            catch
            {
                Response.Redirect("khachhang_list.aspx");
            }
        }

        protected void btn_Update_Click(object sender, EventArgs e)
        {
            KHACH_HANGBUS khb = new KHACH_HANGBUS();
            try
            {
                KHACH_HANG k = new KHACH_HANG();
                k.MaKhachHang = int.Parse(MaKH.Value.ToString());
                k.Email = Email.Value;
                k.MatKhau = MatKhau.Value;
                k.TenKhachHang = TenKhachHang.Value;
                k.DiaChi = DiaChi.Value;
                k.DienThoai = DienThoai.Value;
                khb.KhachHang_Sua(k);
                Response.Write("@<script type='text/javascript'>alert('Update thành công'); window.close()</script>");
            }
            catch
            {
                Response.Redirect("khachhang_list.aspx");
            }
        }
    }
}